package com.songlanyun.modules.loverecord.controller.api;

import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;
import com.songlanyun.modules.account.controller.common.AbstractApiController;
import com.songlanyun.modules.loverecord.entity.UserLoveRecordEntity;
import com.songlanyun.modules.loverecord.service.UserLoveRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;


/**
 * 会员爱心值的收支记录
 *
 * @author wuchao
 * @email songlanyun@gmail.com
 * @date 2022-08-09 16:56:00
 */
@RestController
@RequestMapping("/api/user/love/record")
public class UserLoveRecordApiController extends AbstractApiController {
    @Autowired
    private UserLoveRecordService userLoveRecordService;

    /**
     * 列表
     */
    @GetMapping("/page")
    //@RequiresPermissions(":userloverecord:list")
    public R page(@RequestParam Map<String, Object> params) {
        params.put("user_id", getUserId(true));
        PageUtils page = userLoveRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 爱心兑换公益积分
     */
    @PostMapping("/loveValueExchange/{loveValue}")
    //@RequiresPermissions(":userloverecord:list")
    public R loveValueExchange(@PathVariable("loveValue") Integer loveValue) {
        userLoveRecordService.loveValueExchange(getUserId(true), loveValue);

        return R.ok();
    }

}
